<extend name="Public:main" />
<block name="title">买入</block>
<block name="custom_css">
    <style>

    </style>
</block>
<block name="body">
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
    <div class="nav_top flex">
        <a  href="/index.php/Home/Index/index">
            <i></i>
        </a>
        <div class="flex1">
            买入
        </div>
        <a class="more_show" href="javascript:void(0)">
            <i></i>
        </a>
        <div class="list_xz">
            <ul>
                <li>
                    <a href="{:U('Transaction/unOrderList')}">
                        订单
                    </a>
                </li>
                <li>
                    <a href="{:U('Transaction/buyinLoglist')}">
                        买入记录
                    </a>
                </li>
                <li>
                    <a href="javascript:void(0);" ng-click="jump_buy_center()">
                        买入中心
                    </a>
                </li>
            </ul>
        </div>

    </div>
    <div style="height: 0.44rem;"></div>
    <p class="l_tit">请选择买入数额</p>
    <div class="cz_list clearfix">
        <ul>
            <volist name="transaction_num" id="vo1" key="k">
                <li value="<php>echo $vo1;</php>" <if condition="$k eq 1">class="active5"</if> >
                    {$vo1}
                </li>
            </volist>
        </ul>
    </div>
    <if condition="$db_flag eq 0">
        <a class="add_bank" href="{:U('Transaction/bankList_purchase')}">
            <i></i>
            <p>请选择银行卡</p>
        </a>
    <elseif condition="$db_flag eq 1"/>
        <div class="bank_show">
            <a href="{:U('Transaction/bankList_purchase')}" style="font-size: 0.15rem;padding-bottom: 0.05rem;">
                绑定的银行卡
                <i></i>
            </a>
            <div>
                <input type="hidden" id="bankcardid"  value="{$default_bankcard.id}">
                {$default_bankcard.realname}
            </div>
            <div>
                {$default_bankcard.bankname}
            </div>
            <div>
                <label for="">
                    银行卡号：{$default_bankcard.no}
                </label>
            </div>
        </div>
    </if>
    <input type="button" name="" class="login_btn" value="创建订单">
    <div class="masks"></div>
    <div class="pwd-box">
        <input type="tel" maxlength="6" class="pwd-input" id="pwd-input">
        <div class="fake-box">
            <input type="password" readonly="">
            <input type="password" readonly="">
            <input type="password" readonly="">
            <input type="password" readonly="">
            <input type="password" readonly="">
            <input type="password" readonly="">
        </div>
        <label>
            输入支付密码
        </label>
    </div>

</body>
    <block name="custom_js">
        <script src="http://zeptojs.com/zepto.min.js"></script>
        <script>
            $(".more_show").click(function(){
                $(".list_xz").slideToggle();
            });
        </script>
        <script>
            var app = getApp('myApp', []);
            app.controller('Ctrl', function ($scope, $http) {
                var $input = $(".fake-box input");
                var bankcardid = $("#bankcardid").val();
                $scope.bankcardid = bankcardid;
                $("#pwd-input").on("input", function() {
                    var pwd = $(this).val().trim();
                    for (var i = 0, len = pwd.length; i < len; i++) {
                        $input.eq("" + i + "").val(pwd[i]);
                    }
                    $input.each(function() {
                        var index = $(this).index();
                        if (index >= len) {
                            $(this).val("");
                        }
                    });
                    if (len == 6) {
                        //执行其他操作
                        var num = '';
                        $input.each(function() {
                            num += $(this).val().trim()
                        });

                        var sum = $(".active5").val();

                        if (num.length != 6) {
                            layer.msg("请输入您6位数字支付密码！");
                            return;
                        }
                        if (sum == 'undefined' || sum == undefined || sum == 'null' || sum == null) {
                            layer.msg("请刷新页面重试！");
                            return;
                        }
                        if (bankcardid == 'undefined' || bankcardid == undefined || bankcardid == 'null' || bankcardid == null) {
                            layer.msg("请选择银行卡！");
                            location.reload();
                            return;
                        }

                        $scope.sub(num, sum, bankcardid);
                    }
                });

                $scope.sub=function (num, sum, bankcardid) {
                    $http({
                        method:'POST',
                        data:{
                            "num" : num,
                            "sum" : sum,
                            "bankcardid" : bankcardid,
                        },
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: function(obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Transaction/purchase"
                    }).then(function successCallback(response) {
                        if(response.data.code==0){
                            layer.msg("操作成功！");
                            setTimeout(function () {
                                window.location.href = '/index.php/Home/Transaction/unOrderList';
                            }, 1000);
                        }else {
                            if(response.data.msg != '' && response.data.msg != null) {
                                layer.msg(response.data.msg,{time:1500})
                            }
                        }
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }
                
                $scope.jump_buy_center=function () {
                    console.log($scope.bankcardid);
                    if ($scope.bankcardid == 'undefined' || $scope.bankcardid == undefined || $scope.bankcardid == '') {
                        layer.msg("请选择银行卡");
                        return;
                    } else {
                        window.location.href='/index.php/Home/Transaction/buy_center?id=' + $scope.bankcardid;
                    }
                }
            });
        </script>
    </block>
</block>